package com.gxa.service.discrepancy.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.entity.discrepancy.Track;
import com.gxa.entity.discrepancy.search.TrackSearchMap;
import com.gxa.mapper.discrepancy.TrackMapper;
import com.gxa.service.discrepancy.TrackService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:43:53
 */
@Service
public class TrackServiceImpl extends ServiceImpl<TrackMapper, Track> implements TrackService {

    @Autowired
    private TrackMapper mapper;
    @Override
    public PageInfo<Track> queryByPage(TrackSearchMap map) {
        PageHelper.startPage(map.getPageNum(),map.getPageSize());//1.开启分页

        QueryWrapper<Track> wrapper = new QueryWrapper<>();//2.条件构造器 模拟写动态sql  或者在xml 中写
        if (map.getCatchNo() != null && map.getCatchNo() != 0) {
            wrapper.like("pic_number", map.getCatchNo());
        }

        if(map.getPersonType() != null && map.getPersonType() != 0){
            wrapper.like("owner_type",map.getPersonType());
        }
        if(!StringUtils.isAnyBlank(map.getStartTime(),map.getEndTime())){
            wrapper.between("camera_time",map.getStartTime(),map.getEndTime());
        }
        PageInfo<Track> pageInfo = new PageInfo<>(mapper.selectByPage(wrapper));//3.获取分页信息
        return pageInfo;
    }
}
